from django.db import models
# Create your views here.
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    """自定义用户模型类"""

    def __str__(self):
        return self.username

    mobile = models.CharField(max_length=11, unique=True, verbose_name='手机号')

    class Meta:
        db_table = 'tb_users'  # 自定义表明
        verbose_name = verbose_name_plural = "用户"  # 表名



#
# class Category(models.Model):
#     def __str__(self):
#         return self.name
#
#     STATUS_NORMAL = 1
#     STATUS_DELETE = 0
#     STATUS_ITEMS = (
#         (STATUS_NORMAL, '正常'),
#         (STATUS_DELETE, '删除'),
#     )
#
#     name = models.CharField(max_length=50, verbose_name="名称")
#     status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=STATUS_ITEMS, verbose_name="状态")
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
#     is_nav = models.BooleanField(default=False, verbose_name="是否为导航")
#     owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="作者")
#
#     class Meta:
#         verbose_name = verbose_name_plural = "分类"
#
#     @classmethod
#     def get_navs(cls):
#         categories = cls.objects.filter(status=cls.STATUS_NORMAL)
#         nav_categories = []
#         normal_categories = []
#         for cate in categories:
#             if cate.is_nav:
#                 nav_categories.append(cate)
#             else:
#                 normal_categories.append(cate)
#         return {'navs': nav_categories, 'categories': normal_categories}